<?php
require_once("Tool.php");

Class AttachmentList{
  
  function __construct() {
		}	
		
  function setAttachment($nid, $path)
  {
  	require_once("Dbcon.php");
  	$dbc = new Dbcon();
	
	$sql = "insert into attachment(nid, filename, status, created_date, updated_date) values('" . $nid . "', '" . $path . "', 'true', DATE_ADD(NOW(), INTERVAL 15 HOUR),DATE_ADD(NOW(), INTERVAL 15 HOUR))";
	$result = $dbc->setInsert($sql);
	$dbc->clear();	
	
	return $result;
  }
  
  function updateAttachment($nid, $path)
  {
  	require_once("Dbcon.php");
  	$dbc = new Dbcon();
	
	$sql = "update attachment set filename = '" . $path . "', status = 'true', updated_date = DATE_ADD(NOW(), INTERVAL 15 HOUR) where nid = " . $nid;
	$result = $dbc->setUpdate($sql);
	$dbc->clear();	
	
	return $result;
  }
  
  function deleteAttachment($nid)
  {
  	require_once("Dbcon.php");
  	$dbc = new Dbcon();
	
	$sql = "update attachment set status = 'false', updated_date = DATE_ADD(NOW(), INTERVAL 15 HOUR) where nid = " . $nid;
	$result = $dbc->setUpdate($sql);
	$dbc->clear();	
	
	return $result;
  }
  
  function existAttachment($nid)
  {
  	require_once("Dbcon.php");
  	$dbc = new Dbcon();
	
	$sql = "select count(*) total from attachment where nid = " . $nid;
	$result = $dbc->getSelect($sql);
	$dbc->clear();	
	
	if ($result[0]['total'] != "0")
	  return true;
    else
	  return false;
  }
   
}
?>